package com.sgb.kjwl.viewmodel.manage;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.view.ui.fragment.manage.CompanyPropertyFragment;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CompanyPropertyModel{

    CompanyPropertyFragment companyPropertyFragment;

    public CompanyPropertyModel(CompanyPropertyFragment companyPropertyFragment) {
        this.companyPropertyFragment = companyPropertyFragment;
    }

    public void getCompanyAssetsType(){
        DialogHelper.showProgressDialog(companyPropertyFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getCompanyAssetsType().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<IpPickSelectEntity> list = new ArrayList<>();
                    list.add(0,new IpPickSelectEntity("","全部","","","","",""));
                    list.addAll(response.body().getData());
                    companyPropertyFragment.getCompanyAssetsType(list);
                } else {
                    MToast.showToast(companyPropertyFragment.getContext().getApplicationContext(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}